package com.karrysong.blog_springboot.controller;

import com.karrysong.blog_springboot.service.CategoryService;
import com.karrysong.blog_springboot.vo.Result;
import com.karrysong.blog_springboot.vo.params.CategoryPage;
import com.karrysong.blog_springboot.vo.params.CategoryParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName: Category
 * @Author: KarrySong
 * @Date: 2022/8/7 9:16
 * @Description:
 */
@RestController
@RequestMapping("/categories")
public class CategoryController {

    @Autowired
    private CategoryService categoryService;

    @GetMapping
    public Result listCategories(){
        return categoryService.findAll();
    }

    /*@GetMapping("/detail")
    public Result categoriesDetail(){
        return categoryService.findAllDetail();
    }*/

    @GetMapping("/detail/{id}")
    public Result categoryDetailById(@PathVariable("id") Long id){
        return Result.success(categoryService.findCategoryById(id));
    }

    @PostMapping("/admin/all")
    public Result getCategories(@RequestBody CategoryPage categoryPage){
        return categoryService.getCategories(categoryPage);
    }

    @PostMapping("/admin/change")
    public Result updateCategory(@RequestBody CategoryParam categoryParam){
        return categoryService.updateCategory(categoryParam);
    }

    @PostMapping("/admin/add")
    public Result addCategory(@RequestBody CategoryParam categoryParam){
        return categoryService.addCategory(categoryParam);
    }

    @PostMapping("/admin/delete/{id}")
    public Result deleteCategory(@PathVariable Long id){
        return categoryService.deleteCategory(id);
    }

    @GetMapping("/admin/deleteList")
    public Result deleteCategoryList(Long[] arr){
        return categoryService.deleteCategoryList(arr);
    }


}
